package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.ReadingEveryDayDateBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 07.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class DailyReadingPagerAdapter extends PagerAdapter {
    private List<ReadingEveryDayDateBean.DataBean> mlist =new ArrayList<>();
    private Context mcontext;
    public DailyReadingPagerAdapter(List<ReadingEveryDayDateBean.DataBean> bean, Context context) {
        mlist.addAll(bean);
        mcontext = context;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = View.inflate(container.getContext(), R.layout.item_daily_reading,null);
        ImageView iv_raw = (ImageView) view.findViewById(R.id.item_daily_reading_iv_raw);
        TextView tv_content = (TextView) view.findViewById(R.id.item_daily_reading_tv_content);
        Glide.with(mcontext).load(RBConstants.SERVER_URL+"/Public/Uploads/"+mlist.get(position).art_url).into(iv_raw);
        tv_content.setText(mlist.get(position).comefrom);
        container.addView(view);
        return view;
    }
}
